 

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>头盔检测系统-数据库管理</title>
    <link rel="stylesheet" type="text/css" href="EasyUI/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="EasyUI/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="EasyUI/themes/color.css">
    <link rel="stylesheet" type="text/css" href="EasyUI/demo.css">
    <script type="text/javascript" src="EasyUI/jquery.min.js"></script>
    <script type="text/javascript" src="EasyUI/jquery.easyui.min.js"></script>
    <script src="helmet.js"></script>
</head>
<body style=" background: #00bbee;">
<div style="padding: 20px;">
    <div style="text-align: left; font-size: 12px;">欢迎 <span id="userNameForWelcome">用户名</span> </div>
    <div id="tabContainer" class="easyui-tabs" style=" background: whitesmoke; height: 600px">
            <!-- 第一个标签页 -->
            <div title="用户管理" closable="false">

                <table id="dgUser" title="用户列表" class="easyui-datagrid"
                       toolbar="#usertoolbar" pagination="false"
                       rownumbers="true" fitColumns="true" singleSelect="true">
                    <thead>
                    <tr>
                        <th field="id" width="50">id</th>
                        <th field="name" width="50">名字</th>
                        <th field="password" width="50">密码</th>
                        <th field="func" width="50">功能权限</th>
                        <th field="provinceId" width="50">省id</th>
                        <th field="provinceName" width="50">省名</th>
                        <th field="cityId" width="50">市id</th>
                        <th field="cityName" width="50">市名</th>
                        <th field="districtId" width="50">区id</th>
                        <th field="districtName" width="50">区名</th>
                        <th field="blockId" width="50">块id</th>
                        <th field="blockName" width="50">块名</th>
                    </tr>
                    </thead>
                </table>
                <div id="usertoolbar">
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增用户</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑用户</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除用户</a>
                </div>

                <div id="dlgUser" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlgUser-buttons'">
                    <form id="fmUser" method="post" novalidate style="margin:0;padding:20px 50px">
                        <h3>用户信息</h3>
                        <div style="margin-bottom:10px">
                            <label for="userId">id:</label>
                            <input id="userId" name="id" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="name">名字:</label>
                            <input id="name" name="name" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="password">密码:</label>
                            <input id="password" name="password" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="func">功能权限:</label>
                            <input id="func" name="func" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="provinceId">省id:</label>
                            <input id="provinceId" name="provinceId" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="provinceName">省名:</label>
                            <input id="provinceName" name="provinceName" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="cityId">市id:</label>
                            <input id="cityId" name="cityId" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="cityName">市名:</label>
                            <input id="cityName" name="cityName" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="districtId">区id:</label>
                            <input id="districtId" name="districtId" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="districtName">区名:</label>
                            <input id="districtName" name="districtName" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="userBlockId">块id:</label>
                            <input id="userBlockId" name="blockId" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="blockName">块名:</label>
                            <input id="blockName" name="blockName" class="easyui-textbox" required style="width:70%">
                        </div>
                    </form>
                </div>
                <div id="dlgUser-buttons">
                    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">保存</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgUser').dialog('close')" style="width:90px">取消</a>
                </div>
            </div>
            <!-- 第二个标签页 -->
            <div title="摄像头管理" closable="false">
                <table id="dgCamera" title="摄像头列表" class="easyui-datagrid"
                       toolbar="#cameratoolbar" pagination="false"
                       rownumbers="true" fitColumns="true" singleSelect="true">
                    <thead>
                    <tr>
                        <th field="id" width="50">id</th>
                        <th field="blockId" width="50">所属块</th>
                        <th field="url" width="50">url</th>
                        <th field="working" width="50">可用</th>
                    </tr>
                    </thead>
                </table>
                <div id="cameratoolbar">
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newCamera()">新增摄像头</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editCamera()">编辑摄像头</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyCamera()">删除摄像头</a>
                </div>

                <div id="dlgCamera" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlgCamera-buttons'">
                    <form id="fmCamera" method="post" novalidate style="margin:0;padding:20px 50px">
                        <h3>摄像头信息</h3>

                        <div style="margin-bottom:10px">
                            <label for="cameraBlockId">所属块id:</label>
                            <input id="cameraBlockId" name="blockId" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="url">url:</label>
                            <input id="url" name="url" class="easyui-textbox" required style="width:70%">
                        </div>
                        <div style="margin-bottom:10px">
                            <label for="working">可用:</label>
                            <input id="working" name="working" class="easyui-textbox" required style="width:70%">
                        </div>
                    </form>
                </div>
                <div id="dlgCamera-buttons">
                    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveCamera()" style="width:90px">保存</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgCamera').dialog('close')" style="width:90px">取消</a>
                </div>


            </div>

        </div>

    <div style="text-align: right; position: absolute; bottom: 20px; right: 20px;">
        <button  onclick="exitSystem()">退出系统</button>
    </div>
</div>
<script>
    //页面加载
    $(document).ready(function() {
        welcome().then(user => {
            if (user) {
                checkFunc(user.func);
                document.getElementById('userNameForWelcome').innerText = user.name;
                initCameraList(user);
                //initDefaultPopedom(user);
            }
            else
                exitSystem();
        });
    })

    //检查功能权限, 无权限则退出系统
    function checkFunc(func){
        if(func != 1){//不是管理员权限
            alert("无此功能权限");
            window.location.href = 'login.html';
        }
    }
    //用户管理部分
    $(function() {//页面加载完毕后, 读取并显示数据库内容
        $('#dgUser').datagrid({
            singleSelect : false,
            url : 'user/list',
            queryParams : {}, //查询条件
            pagination : false, //启用分页
            rownumbers : true, //显示行号
            fit : true, //设置自适应
            toolbar : '#usertoolbar', //为datagrid添加工具栏
            header : '#searchUserListTb', //为datagrid标头添加搜索栏
            columns : [ [ { //编辑datagrid的列
                title : '序号',
                field : 'id',
                align : 'center',
                checkbox : true
            }, {
                field : 'name',
                title : '名字',
                width : 100
            }, {
                field : 'password',
                title : '密码',
                width : 100
            }, {
                field : 'func',
                title : '功能权限',
                width : 80
            },   {
                title : '省id',
                field : 'provinceId',
                width: 100
            }, {
                field : 'provinceName',
                title : '省名',
                width : 100
            }, {
                field : 'cityId',
                title : '市id',
                width : 100
            }, {
                field : 'cityName',
                title : '市名',
                width : 100
            }, {
                title : '区id',
                field : 'districtId',
                width: 100
            }, {
                field : 'districtName',
                title : '区名',
                width : 100
            }, {
                field : 'blockId',
                title : '块id',
                width : 100
            }, {
                field : 'blockName',
                title : '块名',
                width : 100
            }, ] ]
        });
    });
    var url;
    function newUser(){
        $('#dlgUser').dialog('open').dialog('center').dialog('setTitle','新增用户');
        $('#fmUser').form('clear');
        url = 'user/addUser';//设置参数url为目标地址, 供下面保存时使用
    }
    function editUser(){
        var row = $('#dgUser').datagrid('getSelected');
        if (row){
            $('#dlgUser').dialog('open').dialog('center').dialog('setTitle','编辑用户信息');
            $('#fmUser').form('load',row);
            url = 'user/updateUser?id='+row.id;
        }
    }
    function saveUser(){
        $('#fmUser').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = JSON.parse(result);
                if (result.errorMsg){
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#dlgUser').dialog('close');        // close the dialog
                    $('#dgUser').datagrid('reload');    // reload the user data
                }
            },
            error: function (){
                $.messager.show({
                    title: 'Error',
                    msg: "提交失败"
                })
            }
        });
    }
    function destroyUser(){
        var row = $('#dgUser').datagrid('getSelected');
        if (row){
            $.messager.confirm('Confirm','确认删除用户?',function(r){
                if (r){
                    $.post('user/deleteUser',{id:row.id},function(result){
                        if (result.success){
                            $('#dgUser').datagrid('reload');    // reload the user data
                        } else {
                            $.messager.show({    // show error message
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    },'json');
                }
            });
        }
    }




    //摄像头管理部分
    $(function() {//页面加载完毕后, 读取并显示数据库内容
        $('#dgCamera').datagrid({
            singleSelect : false,
            url : 'camera/list',
            queryParams : {}, //查询条件
            pagination : false, //启用分页
            rownumbers : true, //显示行号
            fit : true, //设置自适应
            toolbar : '#cameratoolbar', //为datagrid添加工具栏
            header : '#searchCameraListTb', //为datagrid标头添加搜索栏
            columns : [ [ { //编辑datagrid的列
                title : '序号',
                field : 'id',
                align : 'center',
                checkbox : true
            }, {
                field : 'blockId',
                title : '所属块id',
                width : 100
            }, {
                field : 'url',
                title : 'url',
                width : 100
            }, {
                title : '可用',
                field : 'working',
                width: 100
            }] ]
        });
    });
    var cameraRequstUrl;
    function newCamera(){
        $('#dlgCamera').dialog('open').dialog('center').dialog('setTitle','新增摄像头');
        $('#fmCamera').form('clear');
        cameraRequstUrl = 'camera/addCamera';//设置参数cameraRequstUrl为目标地址, 供下面保存时使用
    }
    function editCamera(){
        var row = $('#dgCamera').datagrid('getSelected');
        if (row){
            $('#dlgCamera').dialog('open').dialog('center').dialog('setTitle','编辑摄像头信息');
            $('#fmCamera').form('load',row);
            cameraRequstUrl = 'camera/updateCamera?id='+row.id;
        }
    }
    function saveCamera(){
        $('#fmCamera').form('submit',{
            url: cameraRequstUrl,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = JSON.parse(result);
                if (result.errorMsg){
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#dlgCamera').dialog('close');        // close the dialog
                    $('#dgCamera').datagrid('reload');    // reload the user data
                }
            },
            error: function (){
                $.messager.show({
                    title: 'Error',
                    msg: "提交失败"
                })
            }
        });
    }
    function destroyCamera(){
        var row = $('#dgCamera').datagrid('getSelected');
        if (row){
            $.messager.confirm('Confirm','确认删除摄像头?',function(r){
                if (r){
                    $.post('camera/deleteCamera',{id:row.id},function(result){
                        if (result.success){
                            $('#dgCamera').datagrid('reload');    // reload the user data
                        } else {
                            $.messager.show({    // show error message
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    },'json');
                }
            });
        }
    }
    $(function() {
        // 初始化标签页
        $('#tabContainer').tabs()
    });


</script>

</body>
</html>